package com.neusoft.databus.policy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.databus.policy.enums.PolicyType;
import com.neusoft.databus.policy.repository.PolicyRepository;
import com.neusoft.databus.policy.service.EventService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 统计控制器
 * 
 * @author naxiang
 */
@Api("统计控制器")
@RestController("policyStatisticController")
@RequestMapping(value = "/api/w/statistics")
public class StatisticController {
    @Autowired
    private PolicyRepository policyRepository;
    @Autowired
    private EventService eventService;

    @ApiOperation("策略统计")
    @GetMapping("/policy/count")
    public ResultDTO<Long> policyCount() {
        final long count = this.policyRepository.count();
        return ResultDTO.success(count);
    }

    /**
     * 查询告警事件数量
     * 
     * @param policyType
     * @return
     */
    @ApiOperation("查询告警事件数量")
    @GetMapping("/eventCount/{policyType}")
    public ResultDTO<Integer> eventCount(@PathVariable PolicyType policyType) {
        Integer eventCount = this.eventService.eventCount(policyType);
        return ResultDTO.success(eventCount);
    }
}
